<{include file="public_html/header.html"}>
<{include file="public_html/left_menu.html"}>
<style>
	.acc-data-selector{background-color:#fff;border:1px solid #d8d8d8;position:absolute;width:570px;z-index:999}
.acc-data-selector-selected{border-right:1px solid #d8d8d8;font-size:0;margin-right:37px;max-height:108px;min-height:36px;overflow:auto;padding:8px 0 0 8px; height:42px;}
.acc-data-selector-selected .item{border:1px solid #eaeaea;color:#949494;cursor:pointer;display:inline-block;font-size:12px;height:26px;line-height:26px;margin:0 8px 0px 0;overflow:hidden;position:relative;text-indent:6px;width:116px}
.acc-data-selector-selected .item .iclose{background-color:#fff;height:26px;position:absolute;right:0;top:0;width:20px;font-weight:400}
.acc-data-selector-selected .item:hover{border-color:#36b888;color:#36b888}
.acc-data-selector-selected .item:hover .iclose{background-color:#36b888;color:#fff}
.acc-data-selector-table{border-top:1px solid #d8d8d8;font-size:14px;overflow:hidden; background:url(/static/school/images/zj_bg.png) repeat-y; min-height:200px;;}
.acc-data-selector-close{background:rgba(0,0,0,0) url(/static/school/images/check.png) no-repeat scroll -28px 0;cursor:pointer;height:12px;position:absolute;right:10px;top:8px;width:18px}
.acc-data-selector-empty{display:block;font-size:16px;padding:0;text-align:center}
.acc-data-selector-group{background-color:#f3f3f3;float:left;padding:12px 0;text-indent:24px;width:104px; margin:0;}
.acc-data-selector-group .title{cursor:pointer;overflow:hidden;padding:6px 0;text-overflow:ellipsis;white-space:nowrap}
.acc-data-selector-group .title:hover{background-color:#9fc}
.acc-data-selector-group .active{background-color:#43bc8f;color:#fff;visibility:visible}
.acc-data-selector-list{overflow:auto;padding:12px 0}
.acc-data-selector-loading{display:none;font-size:16px;position:relative;text-align:center;top:100px}
.acc-data-selector-items li{cursor:pointer;padding:6px 0 6px 20px}
.acc-data-selector-items .title{font-weight:700}
.acc-data-selector-items .ico-check{background:url(/static/school/images/check.png) no-repeat;display:inline-block;height:14px;margin-right:10px;vertical-align:middle;width:14px}
.acc-data-selector-items .checked .ico-check{background-position:-14px 0}
</style>
<blockquote class="layui-elem-quote"><{$action}></blockquote>

<form class="layui-form " method="post" action="/tiku/add_test_volume">
	<div class="item m-b10 add_step" <{if $subject_id > 0}>style="display:none;"<{/if}>>
		<div class="layui-form-item">
			<label class="layui-form-label">试卷名称</label>
			<div class="layui-input-block">
				<input type="text" name="name" id="name" value="<{$test_volume_name}>" class="layui-input" />
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">科目</label>
			<div class="layui-input-inline">
				<select name="subject_id" id="subject_id" class="text">
					<{foreach from=$subject item=item}>
					<option value="<{$item.id}>" <{if $subject_id > 0 AND $subject_id == $item.id}>selected<{/if}>><{$item.title}></option>
					<{/foreach}>
				</select>
			</div>
		</div>

		<div class="layui-input-block">
			<input type="button" class="layui-btn" id="select_subject" value="下一步" />
			<input type="reset" class="layui-btn layui-btn-primary" value="重置" />
		</div>
	</div>

	<!--步骤二-->
	<div class="item m-b10 add_step" <{if $subject_id == 0}>style="display:none;"<{/if}>>
		<div class="layui-form-item">
			<label class="layui-form-label">组卷名称</label>
			<div class="layui-input-block">
				<input type="text" disabled value="<{$test_volume_name}>" class="layui-input" />
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">题目来源</label>
			<div class="layui-input-block">
				<select name="topic_source" id="source_type" lay-filter="source_type">
					<option value="1" selected>系统题目</option>
				</select>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">出题范围</label>
			<div class="layui-input-block acc-data-selector-selected" id="selected_chapter">
				<div style="float:left; width:100px;"><input class="layui-btn layui-btn-warm" id="chapter_id" value="选择章节" type="button" style="font-size: 14px;"></div>
				<div style="float:left;" id="selected_chapter"> </div>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">出题类型</label>
			<div class="layui-input-block">
				<input type="radio" name="create_topic_type" value="1" checked  title="系统出题" lay-filter="create_topic_type">
				<input type="radio" name="create_topic_type" value="2"  title="自主出题" lay-filter="create_topic_type">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">组卷模版</label>
			<div class="layui-input-block">
				<select name="template_id" id="template_id" lay-filter="template_id">
					<option value="">请选择模版</option>
					<option value="0">自定义模版</option>
					<{foreach from=$templates item=template}>
						<option value="<{$template.id}>"><{$template.template_name}></option>
					<{/foreach}>
				</select>
			</div>
		</div>

		<div class="layui-form-item" id="template_name" style="display: none;">
			<label class="layui-form-label">模版名称</label>
			<div class="layui-input-block">
				<input type="text" id="template_name_text" value=""  class="layui-input"/>
			</div>
		</div>

		<div class="layui-form-item template_box">
		    <label class="layui-form-label">单选题数量</label>
		    <div class="layui-input-inline">
		      	<input value="20" type="text" name="number[1]" lay-verify="number" autocomplete="off" class="layui-input" />
		    </div>
		    <label class="layui-form-label">单题分值</label>
		    <div class="layui-input-inline">
		      	<input value="1" type="text" name="fraction[1]" lay-verify="number" autocomplete="off" class="layui-input" />
		    </div>
		    <div class="layui-form-mid layui-word-aux">分</div>
	  	</div>

	  	<div class="layui-form-item template_box">
		    <label class="layui-form-label">多选题数量</label>
		    <div class="layui-input-inline">
	      		<input value="20" type="text" name="number[2]" lay-verify="number" autocomplete="off" class="layui-input" />
		    </div>
		    <label class="layui-form-label">单题分值</label>
		    <div class="layui-input-inline">
		      	<input value="1" type="text" name="fraction[2]" lay-verify="number" autocomplete="off" class="layui-input" />
		    </div>
		    <div class="layui-form-mid layui-word-aux">分</div>
	  	</div>

	  	<div class="layui-form-item template_box">
		    <label class="layui-form-label">判断题数量</label>
		    <div class="layui-input-inline">
	      		<input value="20" type="text" name="number[3]" lay-verify="number" autocomplete="off" class="layui-input" />
		    </div>
		    <label class="layui-form-label">单题分值</label>
		    <div class="layui-input-inline">
		      	<input value="1" type="text" name="fraction[3]" lay-verify="number" autocomplete="off" class="layui-input" />
		    </div>
		    <div class="layui-form-mid layui-word-aux">分</div>
	  	</div>

	  	<div class="layui-form-item template_box">
		    <label class="layui-form-label">计算分析题数量</label>
		    <div class="layui-input-inline">
	      		<input value="20" type="text" name="number[4]" lay-verify="number" autocomplete="off" class="layui-input" />
		    </div>
		    <label class="layui-form-label">单题分值</label>
		    <div class="layui-input-inline">
		      	<input value="1" type="text" name="fraction[4]" lay-verify="number" autocomplete="off" class="layui-input" />
		    </div>
		    <div class="layui-form-mid layui-word-aux">分</div>
	  	</div>

	  	<div class="layui-form-item template_box">
		    <label class="layui-form-label">不定向选择题数量</label>
		    <div class="layui-input-inline">
	      		<input value="20" type="text" name="number[7]" lay-verify="number" autocomplete="off" class="layui-input" />
		    </div>
		    <label class="layui-form-label">单题分值</label>
		    <div class="layui-input-inline">
		      	<input value="1" type="text" name="fraction[7]" lay-verify="number" autocomplete="off" class="layui-input" />
		    </div>
		    <div class="layui-form-mid layui-word-aux">分</div>
	  	</div>

	  	<div class="layui-form-item template_box">
		    <label class="layui-form-label">名词解释数量</label>
		    <div class="layui-input-inline">
	      		<input value="20" type="text" name="number[8]" lay-verify="number" autocomplete="off" class="layui-input" />
		    </div>
		    <label class="layui-form-label">单题分值</label>
		    <div class="layui-input-inline">
		      	<input value="1" type="text" name="fraction[8]" lay-verify="number" autocomplete="off" class="layui-input" />
		    </div>
		    <div class="layui-form-mid layui-word-aux">分</div>
	  	</div>

	  	<div class="layui-form-item template_box">
		    <label class="layui-form-label">简答题数量</label>
		    <div class="layui-input-inline">
	      		<input value="20" type="text" name="number[9]" lay-verify="number" autocomplete="off" class="layui-input" />
		    </div>
		    <label class="layui-form-label">单题分值</label>
		    <div class="layui-input-inline">
		      	<input value="1" type="text" name="fraction[9]" lay-verify="number" autocomplete="off" class="layui-input" />
		    </div>
		    <div class="layui-form-mid layui-word-aux">分</div>
	  	</div>


		<blockquote class="layui-elem-quote">
		  	<span class="total">作业总分：<i style="color:red;">140</i> 分</span>
			<span class="add_template"><input type="button" class="layui-btn layui-btn-normal layui-btn-radius" id="add_template" value="保存模板" /></span>
			<span class="remove_template" data-tid="" style="display:none">删除模板</span>
		</blockquote>

		<div id="topic_list" style="display:none;">
			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
			  	<legend>答题卡</legend>
			</fieldset>

			<div class="layui-form-item layui-form-text">
			    <label class="layui-form-label">单选题</label>
			    <div class="layui-input-inline" id="type_box_1" style="margin-top: 15px;">
		      		<{section name=sn loop=20}>
					<!-- <span class="type_1 type_span"><{$smarty.section.sn.index+1}></span> -->
					<input class="type_1 type_span" title="<{if $smarty.section.sn.index < 9}>0<{/if}><{$smarty.section.sn.index+1}>" disabled type="checkbox" />
					<{/section}>
			    </div>
		  	</div>

		  	<div class="layui-form-item layui-form-text">
			    <label class="layui-form-label">多选题</label>
			    <div class="layui-input-inline" id="type_box_2" style="margin-top: 15px;">
		      		<{section name=sn loop=20}>
					<!-- <span class="type_1 type_span"><{$smarty.section.sn.index+1}></span> -->
					<input class="type_2 type_span" title="<{if $smarty.section.sn.index < 9}>0<{/if}><{$smarty.section.sn.index+1}>" disabled type="checkbox" />
					<{/section}>
			    </div>
		  	</div>

		  	<div class="layui-form-item layui-form-text">
			    <label class="layui-form-label">判断题</label>
			    <div class="layui-input-inline" id="type_box_3" style="margin-top: 15px;">
		      		<{section name=sn loop=20}>
					<!-- <span class="type_1 type_span"><{$smarty.section.sn.index+1}></span> -->
					<input class="type_3 type_span" title="<{if $smarty.section.sn.index < 9}>0<{/if}><{$smarty.section.sn.index+1}>" disabled type="checkbox" />
					<{/section}>
			    </div>
		  	</div>

		  	<div class="layui-form-item layui-form-text">
			    <label class="layui-form-label">计算分析题</label>
			    <div class="layui-input-inline" id="type_box_4" style="margin-top: 15px;">
		      		<{section name=sn loop=20}>
					<!-- <span class="type_1 type_span"><{$smarty.section.sn.index+1}></span> -->
					<input class="type_4 type_span" title="<{if $smarty.section.sn.index < 9}>0<{/if}><{$smarty.section.sn.index+1}>" disabled type="checkbox" />
					<{/section}>
			    </div>
		  	</div>

		  	<div class="layui-form-item layui-form-text">
			    <label class="layui-form-label" style="width: auto;">不定向选择题</label>
			    <div class="layui-input-inline" id="type_box_7" style="margin-top: 15px;">
		      		<{section name=sn loop=20}>
					<!-- <span class="type_1 type_span"><{$smarty.section.sn.index+1}></span> -->
					<input class="type_7 type_span" title="<{if $smarty.section.sn.index < 9}>0<{/if}><{$smarty.section.sn.index+1}>" disabled type="checkbox" />
					<{/section}>
			    </div>
		  	</div>

		  	<div class="layui-form-item layui-form-text">
			    <label class="layui-form-label" style="width: auto;">名词解释</label>
			    <div class="layui-input-inline" id="type_box_8" style="margin-top: 15px;">
		      		<{section name=sn loop=20}>
					<!-- <span class="type_1 type_span"><{$smarty.section.sn.index+1}></span> -->
					<input class="type_8 type_span" title="<{if $smarty.section.sn.index < 9}>0<{/if}><{$smarty.section.sn.index+1}>" disabled type="checkbox" />
					<{/section}>
			    </div>
		  	</div>

		  	<div class="layui-form-item layui-form-text">
			    <label class="layui-form-label" style="width: auto;">简答题</label>
			    <div class="layui-input-inline" id="type_box_9" style="margin-top: 15px;">
		      		<{section name=sn loop=20}>
					<!-- <span class="type_1 type_span"><{$smarty.section.sn.index+1}></span> -->
					<input class="type_9 type_span" title="<{if $smarty.section.sn.index < 9}>0<{/if}><{$smarty.section.sn.index+1}>" disabled type="checkbox" />
					<{/section}>
			    </div>
		  	</div>

			<div id="type_1"></div>
			<div id="type_2"></div>
			<div id="type_3"></div>
			<div id="type_4"></div>
			<div id="type_7"></div>
			<div id="type_8"></div>
			<div id="type_9"></div>
		</div>

		<iframe id="topic_list_box" border=2 frameborder=0 width="100%" marginheight=0 marginwidth=0 scrolling=no style="display:none;">
		</iframe>

		
</form>
<div class="layui-input-block">
	<input type="submit" class="layui-btn" value="下一步" />
</div>
<{include file="public_html/footer.html"}>
<div class="acc-data-selector" style=" display: none;">
		<div class="acc-data-selector-selected">

		</div>
		<{if $chapter_list_data|count  > 0}>
			<div class="acc-data-selector-table">
			<ul class="acc-data-selector-group">
			<{foreach from=$chapter_list_data item=item name=loop}>
				<li class="title act-showItems <{if $smarty.foreach.loop.index == 0}>active<{/if}>" data-gid="1"><{$item.title}></li>
			<{/foreach}>
			</ul>
			<{foreach from=$chapter_list_data item=item key=key name=loop1}>
				<{if isset($item.sub) AND $item.sub|count > 0}>
					<div class="acc-data-selector-list" <{if $smarty.foreach.loop1.index > 0}>style="display: none;"<{/if}>>
					<ul class="acc-data-selector-items">
					<{foreach from=$item.sub item=item1}>
						<li class="item act-checkItem" topic_id="<{$item1.id}>"><i class="ico-check"></i><{$item1.title}></li>
						<!-- <{if isset($item1.sub) AND $item1.sub|count > 0}>
							<{foreach from=$item1.sub item=item2}>
								<li class="item act-checkItem" topic_id="<{$item2.id}>"><i class="ico-check"></i><{$item2.title}></li>
							<{/foreach}>
						<{/if}> -->
					<{/foreach}>
					</ul>
					</div>
				<{/if}>
			<{/foreach}>
			</div>
		<{/if}>
		<i class="acc-data-selector-close act-close"></i>
	</div>
</div>
<script src="/static/school/js/add_test_volume.js" type="text/javascript"></script>
<script>
	$(function(){
		$(".sub-colum").find('li').on('click',function(){//子栏目点击选中状态；
			$(this).addClass('curr').siblings().removeClass('curr');
		})
		$("#add_test_volume").click(function(){
			location.href = "/tiku/add_test_volume";
		})

		layui.use(['form', 'jquery', 'layedit', 'element'], function(){
			var layedit = layui.layedit,form = layui.form(),$ = layui.jquery, element = layui.element();
			layedit.set({
			  	uploadImage: {
			    	url: '/upload/image' //接口url
		  		}
			});
			var subject_text_index = layedit.build("subject_text_index",{height:120})

			layui.form().on('select(q_type)', function(data){
				var type = $(data.elem).val();
				if(type == 1){
					$("#an_checkbox_box, #an_choice_box, #an_analys_box, #an_bdx_box").hide();
					$("#an_radio_box").show();
					$("#an_checkbox_box input[type='text']").attr("lay-verify", "");
					$("#an_choice_box input[type='text']").attr("lay-verify", "");
					$("#an_analys_box input[type='text']").attr("lay-verify", "");
					$("#an_radio_box input[type='text']").attr("lay-verify", "required");
				}else if(type == 2){
					$("#an_radio_box, #an_choice_box, #an_analys_box, #an_bdx_box").hide();
					$("#an_checkbox_box").show();
					$("#an_radio_box input[type='text']").attr("lay-verify", "");
					$("#an_choice_box input[type='text']").attr("lay-verify", "");
					$("#an_analys_box input[type='text']").attr("lay-verify", "");
					$("#an_checkbox_box input[type='text']").attr("lay-verify", "required");
				}else if(type == 3){
					$("#an_radio_box, #an_checkbox_box, #an_analys_box, #an_bdx_box").hide();
					$("#an_choice_box").show();
					$("#an_radio_box input[type='text']").attr("lay-verify", "");
					$("#an_checkbox_box input[type='text']").attr("lay-verify", "");
					$("#an_analys_box input[type='text']").attr("lay-verify", "");
					$("#an_choice_box input[type='text']").attr("lay-verify", "required");
				}else if(type == 4){
					$("#an_radio_box, #an_checkbox_box, #an_choice_box, #an_bdx_box").hide();
					$("#an_analys_box").show();
					$("#an_radio_box input[type='text']").attr("lay-verify", "");
					$("#an_checkbox_box input[type='text']").attr("lay-verify", "");
					$("#an_choice_box input[type='text']").attr("lay-verify", "");
					// $("#an_analys_box input[type='text']").attr("lay-verify", "required");
				}else if(type == 7){
					$("#an_radio_box, #an_checkbox_box, #an_choice_box, #an_analys_box").hide();
					$("#an_bdx_box").show();
					$("#an_radio_box input[type='text']").attr("lay-verify", "");
					$("#an_checkbox_box input[type='text']").attr("lay-verify", "");
					$("#an_choice_box input[type='text']").attr("lay-verify", "");
					$("#an_analys_box input[type='text']").attr("lay-verify", "");
				}else if(type == 8 || type == 9){
					$("#an_radio_box, #an_checkbox_box, #an_choice_box, #an_analys_box, #an_bdx_box").hide();
					$("#an_radio_box input[type='text']").attr("lay-verify", "");
					$("#an_checkbox_box input[type='text']").attr("lay-verify", "");
					$("#an_choice_box input[type='text']").attr("lay-verify", "");
					$("#an_analys_box input[type='text']").attr("lay-verify", "");
				}
			});

			layui.form().on('select(a_type)', function(data){
				var _this = $(data.elem);
				var type = _this.val();
				if(type == 1){
					_this.closest(".layui-tab-item").find(".tk_answer").show();
					_this.closest(".layui-tab-item").find(".fl_answer").hide();
				}else{
					_this.closest(".layui-tab-item").find(".tk_answer").hide();
					_this.closest(".layui-tab-item").find(".fl_answer").show();
				}
			})

			form.on('submit(sub_topic)', function(data){
				var subject_text = $.trim(layedit.getContent(subject_text_index));
				if(subject_text == ''){
					layer.msg('请填写题目内容', {icon: 5, anim: 6});
					return false;
				}

				if($("#subject").val() <= 0){
					layer.msg("请选择科目", {icon:5, anim: 6});
					return false;
				}

				if($("#chapter_id").val() <= 0){
					layer.msg("请选择章节", {icon:5, anim: 6});
					return false;
				}

				if($("#category_id").val() <= 0){
					layer.msg("请选择分类", {icon:5, anim: 6});
					return false;
				}

				if($("#area_code").val() <= 0){
					layer.msg("请选择省份", {icon:5, anim: 6});
					return false;
				}

				/*layer.alert(JSON.stringify(data.field.type), {
				  title: '最终的提交信息'
				})*/
				if($("#q_type").val() == 2){
					checked_dom = 0;
					$("#an_checkbox_box input[type='checkbox']").each(function (index,domEle){
						if($(domEle).next().hasClass("layui-form-checked")){
							checked_dom += 1;
						}
					});
					if(checked_dom < 2){
						layer.msg('多选题至少需要两个正确答案', {icon: 5, anim: 6});
						return false;
					}
				}
			});

			form.on('select(subject)', function(data){
				var ii = layer.load();
				var subject_id = $(data.elem).val();
				$("#chapter_id").html('<option value="0">请选择章节</option>');
				form.render('select');
				$.ajax({
					type: "POST",
					url: "/topic/ignore_get_subject_chapter",
					dataType:"json",
					data:{subject_id:subject_id},
					success: function(result){
						layer.close(ii);
						if(result.code == 1){
							var html ='';
							$.each(result.chapter_list, function(i, obj) {
								html += '<optgroup label="'+ obj.title+'">';
								if(obj.sub){
	                                $.each(obj.sub, function(j, obj1) {
	                                	html += '<option value="'+obj1.id+'">'+obj1.title+'</option>';
	                                });
	                            }
	                            html += '</optgroup>'
							});
							$("#chapter_id").append(html);
							form.render('select');
						}
					}
				});
			});

			$(".add_analys").click(function(){
				var _this = $(this);
				var analys_total = _this.closest(".layui-tab-item").find(".fl_answer").length;
				var analys_sx = parseInt(_this.closest(".layui-tab-item").index())+1;
				var html = '<div class="layui-form-item fl_answer">';
				html +=	'<div class="layui-inline">';
				html +=	'<label class="layui-form-label">借贷方向</label>';
				html +=	'<div class="layui-input-block">';
				html += '<select name="analys[type]['+analys_sx+']['+analys_total+']">';
				html +=	'<option value="1" selected>借</option>';
				html +=	'<option value="2">贷</option>';
				html +=	'</select>';
				html +=	'</div>';
				html +=	'</div>';
				html +=	'<div class="layui-inline">';
				html +=	'<label class="layui-form-label">选择科目</label>';
				html +=	'<div class="layui-input-block">';
				html += '<input type="hidden" class="accounts" name="analys[topic_subject_id]['+analys_sx+']['+analys_total+']">';
				html +=	'<input type="text" autocomplete="off" name="analys[topic_subject_title]['+analys_sx+']['+analys_total+']" class="layui-input" readonly onclick="choice_accounts(this)">';
				html +=	'</div>';
				html +=	'</div>';
				html +=	'<div class="layui-inline">';
				html +=	'<label class="layui-form-label">答案</label>';
				html +=	'<div class="layui-input-block">';
				html +=	'<input type="text" name="analys[answer_text]['+analys_sx+']['+analys_total+']"  autocomplete="off" class="layui-input">';
				html +=	'</div>';
				html +=	'</div>';
				html += '<div class="layui-inline">';
				html += 	'<a href="javascript:;" class="layui-btn layui-btn-primary layui-btn-small del_analys" onclick="del_analys(this)"><i class="layui-icon"></i></a>';
				html += '</div>';
				html +='</div>';
				_this.closest(".fl_answer").before(html);
				form.render('select');
			});

			
		});
	});

	

	function del_analys(obj){
		$(obj).closest(".layui-form-item").remove();
	}

	function choice_accounts(obj){
		$(".accounts").attr("id", "");
		$(".accounts").siblings().attr("id", "");
		$(obj).siblings(".accounts").attr("id", "hidden_id");
		$(obj).attr("id", "hidden_id_text");
		layer.open({
			type: 2,
			title: '选择科目',
			shadeClose: true,
			shade: 0.8,
			area: ['20%', '70%'],
			maxmin: true,
			content: '/tk_accounts_subject/iframe_list' //iframe的url
		}); 
	}
</script>